package com.eos.orm.c3p0.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import com.eos.orm.c3p0.dao.AbstractC3p0Dao;
import com.eos.orm.c3p0.dao.DBConnectionManager;
import com.eos.orm.mybatis.model.ReceiptList;

public class ReceiptListDaoImpl extends AbstractC3p0Dao<ReceiptList> {

	public boolean save(List<ReceiptList> receiptList){
		Connection connection = DBConnectionManager.getConnection();
		String sql = "insert into `receipt_list` (`customer_id`, `activty_id`, `activty_son_id`, `product_id`, `brand_id`, `model_id`, `colour_id`, `case_number`, `bar_code`, `product_count`, `receipt_time`, `insert_user_id`, `insert_time`, `receipt_desc`, `status`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
		boolean flag = false;
		PreparedStatement pstm = null;
		try {
			pstm = connection.prepareStatement(sql);
			for(ReceiptList rl : receiptList){
				pstm.setInt(1, rl.getCustomerId());
				pstm.setInt(2, rl.getActivtyId());
				pstm.setInt(3, rl.getActivtySonId());
				pstm.setInt(4, rl.getProductId());
				pstm.setInt(5, rl.getBrandId());
				pstm.setInt(6, rl.getModelId());
				pstm.setInt(7, rl.getColourId());
				pstm.setString(8, rl.getCaseNumber());
				pstm.setString(9, rl.getBarCode());
				pstm.setInt(10, rl.getProductCount());
				pstm.setString(11, rl.getReceiptTime());
				pstm.setString(12, rl.getInsertUserId());
				pstm.setString(13, rl.getInsertTime());
				pstm.setString(14, rl.getReceiptDesc());
				pstm.setString(15, rl.getStatus());
				pstm.addBatch();
			}
			int[] rlts = pstm.executeBatch();
			if(null != rlts && rlts.length > 0){
				flag = true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			flag = false;
		}finally {
			freeResource(connection, pstm, null);
		}
		return flag;
	}
}
